using System;
using System.Collections.Generic;
using System.Text;
using Impact.Model.Objects;
using Impact.Model.Service;

namespace Impact.UnitTests.Mocks
{
    public class MockPageService : IPageService
    {
        public MockPageService()
        {
            pages = new ImpactPageCollection();


            ImpactPage one = new ImpactPage();
            one.PageId = 1;
            one.PageKey = "one";
            one.Body = "one body";
            one.Caption = "one";
            one.Title = "one";
            one.Sequence = 10;
            one.Type = PageType.Page.TypeId;
            one.Enabled = true;
            pages.Add( one );

            ImpactPage two = new ImpactPage();
            two.PageId = 2;
            two.PageKey = "two";
            two.Body = "two body";
            two.Caption = "two";
            two.Title = "two";
            two.Sequence = 20;
            two.Type = PageType.Page.TypeId;
            two.Enabled = true;
            pages.Add( two );

            ImpactPage three = new ImpactPage();
            three.PageId = 3;
            three.PageKey = "three";
            three.Body = "three body";
            three.Caption = "three";
            three.Title = "three";
            three.Sequence = 30;
            three.Type = PageType.Page.TypeId;
            three.Enabled = false;
            pages.Add( three );

            ImpactPage four = new ImpactPage();
            four.PageId = 4;
            four.PageKey = "four";
            four.Body = "four body";
            four.Caption = "four";
            four.Title = "four";
            four.Sequence = 40;
            four.Type = PageType.Template.TypeId;
            four.Enabled = false;
            pages.Add( four );

            ImpactPage five = new ImpactPage();
            five.PageId = 5;
            five.PageKey = "five";
            five.Title = "five";
            five.LinkTarget = "http://localhost";
            five.Sequence = 50;
            five.Type = PageType.Hyperlink.TypeId;
            five.Enabled = true;
            pages.Add( five );


        }

        private ImpactPageCollection pages;
        public ImpactPageCollection Pages
        {
            get { return pages; }
        }


        #region IPageService Members

        public ImpactPage FetchByID( int pageId )
        {
            return pages.GetList().Find( delegate( ImpactPage page )
            {
                return page.PageId == pageId;
            } );
        }

        public ImpactPageCollection FetchAllPages( bool onlyEnabled )
        {
            throw new Exception( "The method or operation is not implemented." );
        }

        public ImpactPageCollection FetchByTerms( string terms )
        {
            ImpactPageCollection results = new ImpactPageCollection();
            results.AddRange(
                pages.GetList().FindAll( delegate( ImpactPage page )
                {
                    if ( page.PageType.Equals( PageType.Page ) )
                        return page.Body.Contains( terms ) || page.Title.Contains( terms );
                    else
                        return false;
                } )
            );
            return results;
        }

        public TemplateCollection FetchAllTemplates()
        {
            throw new Exception( "The method or operation is not implemented." );
        }

        public ImpactPageCollection FetchChildPages( int parentPageId, bool onlyEnabled )
        {
            throw new Exception( "The method or operation is not implemented." );
        }

        public void Save( ImpactPage page )
        {
            throw new Exception( "The method or operation is not implemented." );
        }

        public void Save( ImpactPage page, Guid userId )
        {
            throw new Exception( "The method or operation is not implemented." );
        }

        public void Remove( int pageId )
        {
            throw new Exception( "The method or operation is not implemented." );
        }

        public ImpactPage FetchByKey( string pageKey )
        {
            return pages.GetList().Find( delegate( ImpactPage page )
            {
                return page.PageKey.Equals( pageKey, StringComparison.CurrentCultureIgnoreCase );
            } );
        }

        #endregion

    }
}
